<html>
<head>
  <title>Evernote Export</title>
  <basefont face="微软雅黑" size="2" />
  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
  <meta name="exporter-version" content="YXBJ Windows/601568 (zh-CN, DDL); Windows/10.0.0 (Win64); EDAMVersion=V2;"/>
  <style>
    body, td {
      font-family: 微软雅黑;
      font-size: 10pt;
    }
  </style>
</head>
<body>
<a name="525"/>
<h1>07-String</h1>
<div>
<table bgcolor="#D4DDE5" border="0">
<tr><td><b>创建时间：</b></td><td><i>2018/4/25 14:57</i></td></tr>
<tr><td><b>更新时间：</b></td><td><i>2020/4/6 22:36</i></td></tr>
<tr><td><b>作者：</b></td><td><i>18081003141@163.com</i></td></tr>
</table>
</div>
<br/>

<div>
<span><div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="text-indent: 0pt;"><span style="font-size: 16pt;"><span style="font-size: 16pt; color: rgb(1, 1, 1); font-weight: bold;">String</span></span></span></div><div><span style="text-indent: 0pt;"><span style="font-size: 16pt;"><span style="font-size: 16pt; color: rgb(1, 1, 1); font-weight: bold;">内置对象</span></span></span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="text-indent: 0pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1);">字符串的两种创建方式（常量和构造函数）</span></span></div><div><span style="text-indent: 0pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1);">字符串常见API(charAt\ indexOf\slice\split\replace)</span></span></div><table style="border-collapse: collapse; min-width: 100%;"><colgroup><col style="width: 254px;"></col><col style="width: 403px;"></col></colgroup><tbody><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>方法</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>描述</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>charAt()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>返回在指定位置的字符。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>indexOf()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>检索字符串，返回下标</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>lastIndexOf()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>从后向前搜索字符串。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>charCodeAt()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>返回在指定的位置的字符的 Unicode 编码。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>fromCharCode()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>从字符编码创建一个字符串。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>concat()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>连接字符串。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div><i>match()</i></div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>找到一个或多个（正则表达式的）匹配。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div><i>replace()</i></div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>替换与正则表达式匹配的子串。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div><i>search()</i></div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>检索与正则表达式相匹配的值。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>slice()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>提取字符串的片断，并在新的字符串中返回被提取的部分。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>split()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>把字符串分割为字符串数组。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div><span style="color: rgb(121, 121, 121);">substr()</span></div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div><span style="color: rgb(121, 121, 121);">从起始索引号提取字符串中指定数目的字符。</span></div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div><span style="color: rgb(121, 121, 121);">substring()</span></div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div><span style="color: rgb(121, 121, 121);">提取字符串中两个指定的索引号之间的字符。</span></div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>toLowerCase()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>把字符串转换为小写。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>toUpperCase()</div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div>把字符串转换为大写。</div></td></tr><tr><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div><span style="text-indent: 28px;"><span style="font-size: 10pt;">trim()</span></span></div></td><td rowspan="1" style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div><span style="text-indent: 28px;"><span style="font-size: 10pt;">去掉字符串前后空格（ES5）</span></span></div></td></tr><tr><td style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>startsWith()</div></td><td style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div><span style="text-indent: 28px; font-size: 10pt;">字符串是否以某个字符开头（ES6）</span></div></td></tr><tr><td style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>endsWith()</div></td><td style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div><span style="text-indent: 28px; font-size: 10pt;">字符串是否以某个字符结尾（ES6）</span></div></td></tr><tr><td style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div>includes()</div></td><td style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div><span style="text-indent: 28px; font-size: 10pt;">字符串是否包含某个字符（ES6）</span></div></td></tr><tr><td style="border: 1px solid rgb(204, 204, 204); width: 254px; padding: 8px;"><div><span style="text-indent: 28px; font-size: 10pt;">repeat()</span></div></td><td style="border: 1px solid rgb(204, 204, 204); width: 403px; padding: 8px;"><div><span style="text-indent: 28px; font-size: 10pt;">重复某个字符串几次（ES6）</span></div></td></tr></tbody></table><div><br/></div><div><br/></div><div><span style="text-indent: 0pt; font-size: 12pt; color: rgb(1, 1, 1);">ASCII码和字符集</span></div><div><br clear="none"/></div><div><span style="text-indent: 0pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1);">字符串常见API(charCodeAt\fromCharCode)</span></span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="font-size: 12pt;"><br/></span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div><div><span style="text-indent: 0pt;"><span style="font-size: 16pt;"><span style="font-size: 16pt; color: rgb(1, 1, 1); font-weight: bold;">练习</span></span></span></div><div><br clear="none"/></div><div><span style="font-size: 12pt; color: rgb(1, 1, 1);">敏感词过滤</span></div><div><span style="font-size: 12pt;"><span style="font-size: 12pt; color: rgb(1, 1, 1); font-family: 微软雅黑, sans-serif;">统计字符串中每个字符的个数，</span></span><span style="font-size: 12pt; text-indent: 0pt; color: rgb(1, 1, 1);">aabccd统计每个字符出现的次数，结果显示 {a： 2，b： 1，c ：2，d：1}</span></div><div><br clear="none"/></div><div><br clear="none"/></div><div><br clear="none"/></div></div><div><br clear="none"/></div><div><br/></div><div><img src="00-string笔记_files/ASCII.jpg" type="image/jpeg" data-filename="ASCII.jpg"/></div><div><br/></div></span>
</div></body></html> 